package com.fishsticks.model;

import java.util.ArrayList;

import com.fishsticks.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class DropDownListAdapter extends ArrayAdapter<Category> {

	private ArrayList<Category> categories;
	
	public DropDownListAdapter(Context context, int textViewResourceId, ArrayList<Category> items) {
		super(context, textViewResourceId, items);
		categories = items;
	}
	
	@Override
	public View getDropDownView(int position, View convertView,	ViewGroup parent) {
		return getCustomView(position, convertView, parent);
	}

	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		return getCustomView(position, convertView, parent);
	}
	
	
	public View getCustomView(int position, View convertView, ViewGroup parent) {
		View newView = convertView;
		
		//Creates a new category list item from the XML resource
        if (newView == null) {
            LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            newView = vi.inflate(R.layout.category_drop_down_item_row, parent, false);
        }
        
        Category currentCategory = categories.get(position);
        
        if (currentCategory != null) {
                TextView titleText  = (TextView) newView.findViewById(R.id.category_text_drop_down);
                
                if (titleText != null) 
                	titleText.setText(currentCategory.getName());
        }
        
        return newView;
	}
	
}
